from datetime import datetime

from django.db import models


# 用户类
class User(models.Model):
    username = models.CharField(max_length=20,unique=True)
    userpasswd  = models.CharField(max_length=100)
    userimg    = models.ImageField(upload_to='upload')
    userphone = models.CharField(max_length=50)
    is_manager = models.BooleanField(default=False)


# 分类
class Tags(models.Model):
    name = models.CharField(max_length=20)



# 文章
class Post(models.Model):
    # 一个用户对应多个博客文章
    user = models.ForeignKey(User, verbose_name='作者')
    # 一篇博客可以有多个标签
    tags = models.ManyToManyField(Tags, verbose_name='标签')
    title = models.CharField('标题', max_length=50)
    content = models.TextField('内容')
    pub_date = models.DateTimeField('发布日期', default=datetime.now)
    # 点击量
    views = models.IntegerField('浏览数', default=0)
    # 物理删除
    is_delete = models.NullBooleanField(default=False)
    # 置顶
    is_top = models.NullBooleanField(default=False)


# 草稿箱
class Draft(models.Model):
    # 一个用户对应多个博客文章
    user = models.ForeignKey(User, verbose_name='作者')
    # 一篇博客可以有多个标签
    tags = models.ManyToManyField(Tags, verbose_name='标签')
    title = models.CharField('标题', max_length=50)
    content = models.TextField('内容')
    pub_date = models.DateTimeField('发布日期', default=datetime.now)
    # 点击量
    views = models.IntegerField('浏览数', default=0)

# 评论
class Comment(models.Model):
    post = models.ForeignKey(Post)
    user = models.ForeignKey(User)
    pub_date = models.DateTimeField('发布时间')
    content = models.TextField('内容')


